define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'resource/xm_programme/index' + location.search,
                    add_url: 'resource/xm_programme/add',
                    edit_url: 'resource/xm_programme/edit',
                    del_url: 'resource/xm_programme/del',
                    multi_url: 'resource/xm_programme/multi',
                    import_url: 'resource/xm_programme/import',
                    table: 'xm_programme',
                }
            });

            var table = $("#table");
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-editone").data("area",[ '100%' , '100%']);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'type.title', title: __('课程类型'), operate: 'LIKE'},

                        {field: 'type_text', title: __('Course_type_id'), searchList: {"1":'铁血训练营',"1":'忆群人团建',"3":'海速体育',"4":'其他'}  , formatter: Table.api.formatter.status},
                        {field: 'purpose.title', title: __('课程目的'), operate: 'LIKE'},
                        {field: 'people_number', title: __('People_number'), searchList: {"1":__('People_number 1'),"2":__('People_number 2'),"3":__('People_number 3'),"4":__('People_number 4'),"5":__('People_number 5'),"6":__('People_number 6')}, formatter: Table.api.formatter.normal},
                        {field: 'days', title: __('Days'), searchList: {"1":__('Days 1'),"2":__('Days 2'),"3":__('Days 3'),"4":__('Days 4'),"6":__('Days 6')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
